package com.bianguo.android.iocdemo.view.activity;

import android.app.Activity;
import android.content.Context;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import com.bianguo.android.injectlibrary.annotations.ContentView;
import com.bianguo.android.injectlibrary.annotations.InjectView;
import com.bianguo.android.injectlibrary.utils.MLog;
import com.bianguo.android.iocdemo.R;
import com.bianguo.android.iocdemo.view.widget.PayPwdView;

@ContentView(R.layout.activity_pay)
public class PayActivity extends BaseActivity implements PayPwdView.OnPwdChangeListener {

    @InjectView(R.id.pay_pwd_view)
    PayPwdView pwdInputView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showKeyBoard();
        pwdInputView.setOnPwdChangeListener(this);
    }

    public void showKeyBoard() {
        Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                showKeyboard(PayActivity.this, pwdInputView);
            }
        }, 500);
    }

    public static void showKeyboard(Activity mContext, EditText editText) {
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        editText.requestFocus();
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editText,1);
    }

    @Override
    public void inputFinished(String pwd) {
        Toast.makeText(this, pwd, Toast.LENGTH_SHORT).show();
    }
}
